package acwing._2LanQiao._4Enumerate;

/**
 * @Project : ProgrammingExercises
 * @Package : ACWing._2LanQiao._4Enumerate
 * @File : Q1245.java
 * @Author : WangRuoyu
 * @Date : 2023/3/15 16:37
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Q1245 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] words = br.readLine().split(" ");
        int n = Integer.parseInt(words[0]);

        int res = 0;
        for (int i = 0; i <= n; ++i) {
            int tmp = i;
            while (tmp != 0) {
                if ((tmp % 10 == 2) || (tmp % 10 == 0) || (tmp % 10 == 1) || (tmp % 10 == 9)) {
                    res += i;
                    break;
                }
                tmp /= 10;
            }
        }
        System.out.println(res);
    }
}


